package com.qianya.oa.controller.system;


import com.qianya.oa.common.core.controller.BaseController;
import com.qianya.oa.common.core.domain.entity.SysUser;
import com.qianya.oa.util.CommonResult;
import com.qianya.oa.util.UploadServiceImpl;
import com.qianya.oa.vo.UploadFileRespVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author LLL
 */
@Slf4j
@Controller
@RequestMapping(value = "/system/upload")
@Api(tags = {"上传管理"})
public class UploadController  extends BaseController {

    @Resource
    private UploadServiceImpl uploadService;
    private String prefix = "system/upload";


    @RequiresPermissions("admin")
    @GetMapping()
    public String upload()
    {
        return prefix+"/upload";
    }

    /**
     * 上传图片
     */
    @PostMapping("/image")
    @ApiOperation(value = "上传图片")
    public CommonResult<UploadFileRespVo> uploadImage(@RequestParam(value = "file") MultipartFile file) throws IOException {
        
        return uploadService.saveImgFile(file);
    }

    /**
     * 上传视频
     */
    @PostMapping("/video")
    @ApiOperation("上传视频")
    public CommonResult<UploadFileRespVo> uploadVideo(@RequestParam(value = "file") MultipartFile file) throws IOException {
        return uploadService.saveVideoFile(file);
    }

    /**
     * 上传MP3
     */
    @PostMapping("/mp3")
    @ApiOperation("上传MP3")
    public CommonResult<UploadFileRespVo> uploadMp3(@RequestParam(value = "file") MultipartFile file) throws IOException {
        return uploadService.saveMP3File(file);
    }
    /**
     * 上传文件
     */
    @ResponseBody
    @PostMapping("/file")
    @ApiOperation("上传文件")
    public CommonResult<UploadFileRespVo> uploadFile(@RequestParam(value = "file") MultipartFile file) throws IOException {
        SysUser sx = getSysUser();
        return uploadService.saveFile(file,sx.getUserId());
    }



}
